package 剑指offer;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @ClassName _09用连个栈实现一个队列
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2022/2/22 19:41
 * Version 1.0
 **/
public class _09用连个栈实现一个队列 {

}
class CQueue {
    Deque stack1 = new LinkedList<Integer>();
    Deque stack2 = new LinkedList<Integer>();

    public CQueue() {

    }

    public void appendTail(int value) {
        stack1.push(value);
    }

    public int deleteHead() {
        if(!stack2.isEmpty()){
            return (int)stack2.pop();
        }else{
            if(stack1.isEmpty()){
                return -1;
            }else{
                while(!stack1.isEmpty()){
                    stack2.push(stack1.pop());
                }
                return (int)stack2.pop();
            }
        }
    }
}